package actions;

import java.io.IOException;
/**
 * 
 * @author cjcj cj.yangjun@gmail.com
 * @date 2011-01-10
 *
 */
public class PowOffPCAct extends DefaultBaseAction implements Action{
	

	public PowOffPCAct(ActionFactory factory) {
		super(factory);
	}
	public static final String cmd="pf";
	
	protected Object call0(){
		String rs="sucess.";
		String osName = System.getProperty("os.name");
		String shutdownCommand="";
		if (osName.startsWith("Win")) {
		  shutdownCommand = "shutdown.exe -f -s -t 0";
		} else if (osName.startsWith("Linux") || osName.startsWith("Mac")) {
		  shutdownCommand = "shutdown -h now";
		} else {
		}
		
		try {
			Process p=Runtime.getRuntime().exec(shutdownCommand);
			p.getOutputStream().close();
			//p.waitFor();
		} catch (IOException e) {
			rs=e.getMessage();
			e.printStackTrace();
			return rs;
		}
		return rs;
	}
	
	public void setHandles(Object... hdls) {
	
	}

	@Override
	public boolean checkCmd(String cmd) {
		// TODO Auto-generated method stub
		return this.cmd.equals(cmd);
	}


}
